// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   ToolPanel.java

package com.boci.common.ui.control;

import com.boci.clientapp.authentication.action.LogoutAction;
import com.boci.clientapp.main.ApplicationService;
import com.boci.clientapp.main.ClientAppLoader;
import com.boci.common.constant.ClientAppConst;
import com.boci.common.util.MessagesConfigurator;
import com.boci.common.util.PerformanceLogger;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Locale;
import javax.swing.*;
import javax.swing.border.EmptyBorder;

// Referenced classes of package com.boci.common.ui.control:
//            CMURLButton, LangBtnsPanel

public class ToolPanel extends JPanel
    implements ActionListener
{

    public ToolPanel(boolean pStandaloneFlag, Locale pLocale)
    {
        initGUI(pStandaloneFlag, pLocale);
    }

    private void initIcon(boolean pStandaloneFlag)
    {
        if(!pStandaloneFlag)
        {
            lblIcon = new JLabel();
            lblIcon.setIcon(ClientAppLoader.getIcon());
            lblIcon.setSize(20, 20);
            add(lblIcon);
        }
    }

    public void setText(Locale pLocale)
    {
        setFont(pLocale);
        setFieldLocation(pLocale);
        langBtnsPanel.setText(pLocale);
        MessagesConfigurator msgConfigurator = ClientAppLoader.getMessagesConfigurator();
        cmbCommonFunctions.setModel(new DefaultComboBoxModel(new String[] {
            msgConfigurator.getUIMessages("COMMON.PLEASE_SELECT", pLocale), msgConfigurator.getUIMessages("COMMON.ACCOUNT_PROFILE", pLocale), msgConfigurator.getUIMessages("COMMON.CHANGE_PASSWORD", pLocale)
        }));
        lblAccount.setText(msgConfigurator.getUIMessages("COMMON.ACCOUNT", pLocale));
        btnAccountGo.setText(msgConfigurator.getUIMessages("COMMON.ACCOUNT_ACTION", pLocale));
        lblCommonFunctions.setText(msgConfigurator.getUIMessages("COMMON.COMMON_FUNCTION", pLocale));
        btnCommonFunctionsGo.setText(msgConfigurator.getUIMessages("COMMON.COMMON_FUNCTION_ACTION", pLocale));
        btnContactUs.setText(msgConfigurator.getUIMessages("COMMON.CONTACT_US", pLocale));
        btnLogout.setText(msgConfigurator.getUIMessages("COMMON.LOGOUT", pLocale));
    }

    private void setFont(Locale pLocale)
    {
        lblAccount.setFont(ClientAppLoader.getSmallBoldTextFont(pLocale));
        btnAccountGo.setFont(ClientAppLoader.getPlainButtonFont(pLocale));
        lblCommonFunctions.setFont(ClientAppLoader.getSmallBoldTextFont(pLocale));
        cmbCommonFunctions.setFont(ClientAppLoader.getSmallPlainTextFont(pLocale));
        btnCommonFunctionsGo.setFont(ClientAppLoader.getPlainButtonFont(pLocale));
        btnContactUs.setFont(ClientAppLoader.getSmallPlainTextFont(pLocale));
        btnLogout.setFont(ClientAppLoader.getPlainButtonFont(pLocale));
    }

    private void setFieldLocation(Locale pLocale)
    {
        if(pLocale.equals(ClientAppConst.EN_US))
        {
            lblAccount.setBounds(16, 1, 60, 20);
            cmbAccount.setBounds(79, 1, 110, 20);
            btnAccountGo.setBounds(192, 1, 22, 20);
            lblCommonFunctions.setBounds(226, 1, 130, 20);
            cmbCommonFunctions.setBounds(358, 1, 150, 20);
            btnCommonFunctionsGo.setBounds(511, 1, 22, 20);
            btnContactUs.setBounds(530, 1, 80, 20);
            langBtnsPanel.setBounds(610, 0, 40, 20);
            btnLogout.setBounds(650, 1, 90, 20);
        } else
        {
            lblAccount.setBounds(16, 1, 60, 20);
            cmbAccount.setBounds(79, 1, 110, 20);
            btnAccountGo.setBounds(192, 1, 40, 20);
            lblCommonFunctions.setBounds(206, 1, 130, 20);
            cmbCommonFunctions.setBounds(338, 1, 150, 20);
            btnCommonFunctionsGo.setBounds(491, 1, 40, 20);
            btnContactUs.setBounds(530, 1, 80, 20);
            langBtnsPanel.setBounds(610, 0, 40, 20);
            btnLogout.setBounds(650, 1, 90, 20);
        }
    }

    public void setAccountNoList(String pAccountNo[], String pPriAccNo)
    {
        cmbAccount.setModel(new DefaultComboBoxModel(pAccountNo));
        cmbAccount.setSelectedItem(pPriAccNo);
    }

    public void reset()
    {
        cmbCommonFunctions.setSelectedIndex(0);
    }

    private void initGUI(boolean pStandalone, Locale pLocale)
    {
        setLayout(null);
        setBorder(new EmptyBorder(0, 0, 0, 0));
        setPreferredSize(new Dimension(750, 22));
        setBackground(Color.WHITE);
        initIcon(pStandalone);
        lblAccount = new JLabel();
        lblAccount.setHorizontalAlignment(4);
        add(lblAccount);
        cmbAccount = new JComboBox();
        add(cmbAccount);
        btnAccountGo = new JButton();
        btnAccountGo.setMargin(new Insets(0, 0, 0, 0));
        add(btnAccountGo);
        lblCommonFunctions = new JLabel();
        lblCommonFunctions.setHorizontalAlignment(4);
        add(lblCommonFunctions);
        btnCommonFunctionsGo = new JButton();
        btnCommonFunctionsGo.setMargin(new Insets(0, 0, 0, 0));
        add(btnCommonFunctionsGo);
        cmbCommonFunctions = new JComboBox();
        add(cmbCommonFunctions);
        btnContactUs = new CMURLButton();
        add(btnContactUs);
        langBtnsPanel = new LangBtnsPanel(pLocale);
        add(langBtnsPanel);
        btnLogout = new JButton();
        add(btnLogout);
        btnAccountGo.setActionCommand("ACCOUNT_GO");
        btnCommonFunctionsGo.setActionCommand("COMMON_FUNCTION_GO");
        btnContactUs.setActionCommand("CONTACT_US");
        btnLogout.setActionCommand("LOGOUT");
        btnAccountGo.addActionListener(this);
        btnCommonFunctionsGo.addActionListener(this);
        btnContactUs.addActionListener(this);
        btnLogout.addActionListener(this);
        setText(pLocale);
    }

    public void actionPerformed(ActionEvent e)
    {
        String strActionType = e.getActionCommand();
        if(strActionType.equals("ACCOUNT_GO") || strActionType.equals("LOGOUT"))
            PerformanceLogger.startAppTimer();
        if(strActionType.equals("ACCOUNT_GO"))
            ApplicationService.getInstance().setAccountNo((String)cmbAccount.getSelectedItem());
        else
        if(strActionType.equals("COMMON_FUNCTION_GO"))
        {
            if(cmbCommonFunctions.getSelectedIndex() == 2)
                ApplicationService.getInstance().showChgPassDialog(true);
            else
            if(cmbCommonFunctions.getSelectedIndex() == 1)
                ApplicationService.getInstance().showViewProfileDialog(true);
            cmbCommonFunctions.setSelectedIndex(0);
        } else
        if(e.getActionCommand().equals("CONTACT_US"))
            ApplicationService.getInstance().showContactUsDialog(true);
        else
        if(e.getActionCommand().equals("LOGOUT"))
        {
            LogoutAction action = new LogoutAction();
            action.doProcess(null, strActionType);
        }
        if(strActionType.equals("ACCOUNT_GO") || strActionType.equals("LOGOUT"))
            PerformanceLogger.stopAppTimer();
        PerformanceLogger.doLog((new StringBuilder()).append("TOOLPANEL.").append(strActionType).toString());
    }

    public void enableAcctNO(boolean enabled)
    {
        cmbAccount.setEnabled(enabled);
        btnAccountGo.setEnabled(enabled);
    }

    private JLabel lblIcon;
    private JLabel lblAccount;
    private JComboBox cmbAccount;
    private JButton btnAccountGo;
    private JLabel lblCommonFunctions;
    private JButton btnCommonFunctionsGo;
    private JComboBox cmbCommonFunctions;
    private CMURLButton btnContactUs;
    private LangBtnsPanel langBtnsPanel;
    private JButton btnLogout;
}
